<?php

require_once dirname(__FILE__).'/../lib/beca_otorgadaGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/beca_otorgadaGeneratorHelper.class.php';

/**
 * beca_otorgada actions.
 *
 * @package    BecArTe
 * @subpackage beca_otorgada
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class beca_otorgadaActions extends autoBeca_otorgadaActions
{
  //lista becas otorgadas del alumno actual
  public function executeMisBecasOtorgadas(sfWebRequest $request){
    $this->becas = $this->getUser()->getAlumno()->getBecasOtorgadas();
    if(!count($this->becas)) $this->getUser()->setFlash('notice','Aún no tiene ninguna beca otorgada.', false);
  }

  //para filtro por alumno
  protected function buildQuery(){
    $qry = parent::buildQuery();    
    $filtros = $this->getFilters();
    if(isset($filtros['alumno']))
       $this->filters->setDefault('alumno', $filtros['alumno']);        
    return $qry;
  }

  public function executeDelete(sfWebRequest $request)
  {
    if($this->getUser()->hasCredential('aspirante')) {
       $becaO = $this->getRoute()->getObject();
       if($becaO->getAlumnoId() != $this->getUser()->getAlumnoId()) {
         $this->getUser()->setFlash('error','No puede finalizar becas de otros beneficiarios');
         $this->redirect('mis_becas');
         return;
       }
       $becaO->setEstado('Finalizada');
       $becaO->save();
       $this->getUser()->setFlash('notice','La beca fue finalizada');
       $this->redirect('mis_becas');
       return;
    }
    return parent::executeDelete($request);
  }

}
